package com.work.keep.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.work.keep.R;
import com.work.keep.datas.SingleWorkoutDataPioneer;
import com.work.keep.volley.VolleySingleton;

import java.util.List;

/**
 * Created by dllo on 16/1/21.
 */
public class MyItemFourRecyclerAdapter extends RecyclerView.Adapter<MyItemFourRecyclerAdapter.MyItemFourViewHolder> {
    private Context context;
    private List<SingleWorkoutDataPioneer.DataEntity> pioneers;
    private VolleySingleton volleySingleton;
    private ImageLoader imageLoader;

    public MyItemFourRecyclerAdapter(Context context, List<SingleWorkoutDataPioneer.DataEntity> pioneers) {
        this.context = context;
        this.pioneers = pioneers;
        volleySingleton = VolleySingleton.getInstance();
        imageLoader = volleySingleton._getImageLoader();
    }

    @Override
    public MyItemFourViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_four_singleworkout_recycler_item, parent, false);
        MyItemFourViewHolder holder = new MyItemFourViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(MyItemFourViewHolder holder, int position) {
        holder.avater.setDefaultImageResId(R.mipmap.ic_launcher);
        holder.avater.setErrorImageResId(R.mipmap.ic_launcher);
        holder.avater.setImageUrl(pioneers.get(position).getAvatar(), imageLoader);
    }

    @Override
    public int getItemCount() {
        return pioneers.size();
    }

    class MyItemFourViewHolder extends RecyclerView.ViewHolder {
        NetworkImageView avater;

        public MyItemFourViewHolder(View itemView) {
            super(itemView);
            avater = (NetworkImageView) itemView.findViewById(R.id.singleWorkoutRecyclerAvater);
        }
    }
}
